﻿// coded with help from Dagradt, TuanHA, and all the dev's who share their time and effort
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.TreeSharp;
using Styx.WoWInternals.DBC;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace CasterPlus
{
    public class CasterPlus : CombatRoutine
    {
        public override Styx.WoWClass Class { get { return Styx.WoWClass.Mage; } }

        public static readonly Version Version = new Version(1, 0, 1);

        public override string Name { get { return "CasterPlus by initrd v" + Version; } }

        public override bool WantButton { get { return true; } }

        public override void OnButtonPress() { standardLog("Gui not yet implemented"); }

        private static LocalPlayer Me { get { return StyxWoW.Me; } }

        public delegate WoWUnit UnitSelection(object unit);

        internal static GroupLogic LocationContext
        {
            get
            {
                Map map = Me.CurrentMap;
                if(map.Battleground || map.IsArena)
                {
                    return GroupLogic.Battleground;
                }
                return map.IsDungeon ? GroupLogic.PvE : GroupLogic.Solo;
            }
        }

        public static string SafeName(WoWUnit unit)
        {
            if (unit != null)
            {
                return (unit.Name == Me.Name) ? "Myself" : unit.Name;
            }
            return "No Target";
        }

        public static void standardLog(string msg, params object[] args)
        {
            if (msg != null)
            {
                Logging.Write(LogLevel.Normal, Colors.DarkOrange, msg, args);
            }
        }

        public override void Initialize()
        {
            TreeRoot.TicksPerSecond = 31;
            standardLog("Hello {0}!", Me.Name);
            standardLog("");
            standardLog("Welcome to CasterPlus");
            standardLog("This is Lazy-Raider/CombatBot Combat Routine");
            standardLog("");
            standardLog("Current Version:");
            standardLog("CasterPlus v" + Version);
            standardLog("by initrd");
            standardLog("");
            standardLog("");
        }

        public override void Pulse()
        {
            if (!StyxWoW.IsInGame || !StyxWoW.IsInGame)
            {
                standardLog("You Died!");
            }
        }

        public override Composite HealBehavior
        {
            get
            {
                return (
                    new PrioritySelector(
                        ));
            }
        }

        public override Composite PreCombatBuffBehavior
        {
	        get 
	        { 
		        return (
                    new Decorator(ret => !Me.Mounted && !Me.IsDead && !Me.Combat && !Me.IsFlying && !Me.IsOnTransport && !Me.HasAura("Food") && !Me.HasAura("Drink"),
                        new PrioritySelector(
                            )));
	        }
        }

        public override Composite CombatBuffBehavior
        {
	        get 
	        { 
		         return (
                     new PrioritySelector(
                         //ice_barrier
                         //icy_veins
                         //arcane_presence
                         //
                         //
                         ));
	        }
        }

        public override Composite CombatBehavior
        {
            get
            {
                return (
                    new Decorator(ret => Me.GotTarget && Me.CurrentTarget != null && Me.CurrentTarget.IsAlive && Me.CurrentTarget.Attackable,
                        new PrioritySelector(
                            new Decorator(ret => Me.CurrentTarget.IsWithinMeleeRange && Unit.CountEnemiesInRange(Me.Location, 8) < 2,
                                new PrioritySelector(
                                    )),
                            new Decorator(ret => Me.CurrentTarget.IsWithinMeleeRange && Unit.CountEnemiesInRange(Me.Location, 8) >= 2,
                                new PrioritySelector(
                                    )),
                            new Decorator(ret => !Me.CurrentTarget.IsWithinMeleeRange && Me.CurrentTarget.DistanceSqr <= 8 * 8 && Unit.CountEnemiesInRange(Me.Location, 8) >= 2,
                                new PrioritySelector(
                                    )),
                            new Decorator(ret => !Me.CurrentTarget.IsWithinMeleeRange && Me.CurrentTarget.DistanceSqr > 8 * 8 && Me.CurrentTarget.DistanceSqr <= 40 * 40 && Unit.CountEnemiesInRange(Me.CurrentTarget.Location, 8) >= 2,
                                new PrioritySelector(
                                    ))

            }
        }
    }
}
